<?php

require_once("../models/config.php");
require_once("../ui.php");
require_once("../stats/db.php");
include_once("bar.graph.php");

if(!isUserLoggedIn()) {
	header ("location: login.php");
	die();
}

global $loggedInUser;
global $db;

function createSQLCommand() {
	
	$sql = "SELECT User_Id AS UserId, Development_Time AS DevelopmentTime, SUM(Debugging_Time) AS DebuggingTime
	 		FROM `debugging_Reports` JOIN `userCake_Users` ON `userCake_Users`.`User_Id` = `debugging_Reports`.`User`
	 		WHERE `userCake_Users`.`Group_Id` = " . STANDART_USER_GROUP_ID . "
			GROUP BY User_Id";
	
	return $sql;
}

$sql = createSQLCommand();
$result = $db->sql_query($sql);
if (!$result) {
	$error = $db->sql_error();
	return;
}

$rows = $db->sql_fetchall();

$data = array();
$ids = array();

foreach($rows as $i => $row) {
	$debugging = floor($row["DebuggingTime"] / 60);
	$development = floor(($row["DevelopmentTime"]) / 60);
	
	$data[] = round(($debugging / $development) * 100); 
	$ids[] = $row["UserId"];
}

drawMyBarGraph($data, "Debugging time / Development time [%]", $ids, "Participant",
 "How much time did the debugging take",
 array("drawLabelsBottom" => TRUE));


?>